package 网络编程.UDP.发送与接受数据;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class 发送数据 {
    public static void main(String[] args) throws IOException {
        //创建发送端的Socket对象DatagramSocket
        DatagramSocket ds =new DatagramSocket();

        //自己封装键盘录入数据
        BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line= br.readLine())!=null){
            //输入数据是886，返送数据结束
            if("886".equals(line))
                break;;
                byte[] bytes =line.getBytes();
            DatagramPacket dp =new DatagramPacket(bytes,bytes.length, InetAddress.getByName("169.254.184.218"),12345);
            //调用DatagramSock对象的方法发送数据
            ds.send(dp);
        }

        //关闭发送端
        ds.close();

    }
}
